package pack.pack2;

import java.util.*;
import java.rmi.*;
import javax.ejb.*;

public class ShoppingCartBean implements SessionBean {
    
    public Vector cart;

    public void addItem(ShoppingCartItem i) {	
	cart.addElement(i);
    }

    public void ejbActivate() {
    }

    public void ejbCreate() {
	cart = new Vector();
    }

    public void ejbPassivate() {
    }

    public void ejbRemove() {
    }

    public ShoppingCartItem getItem(int i) {
	if (i < cart.size()) {
	    return (ShoppingCartItem)this.cart.elementAt(i);
	}
	System.out.println("Wrong...");
       	return null;
    }

    public int getItemCount() {
	return cart.size();
    }

    public void removeItem(ShoppingCartItem i) {
	Enumeration e = cart.elements();
	while (e.hasMoreElements()) {
	    ShoppingCartItem item = (ShoppingCartItem)e.nextElement();
	    if (item.equals(i)) {
		cart.removeElement(item);
	    }
	}
    }
    
    public void setSessionContext(SessionContext ctx) {
    }
}
